import { defineStore } from 'pinia'

export const useTrajectoryStore = defineStore('trajectory', {
  state: () => ({
    searchName: '',
    selectedUserId: '',
    userList: [],
    trajectoryData: [],
    isPlaying: false,
    currentSpeed: 1,
    currentIndex: 0,
    trajectoryLayer: null,
    trajectorySource: null,
    markerFeature: null,
    markerLayer: null,
    markerSource: null,
    queryDialogVisible: false,
    queryParams: {
      startTime: '',
      endTime: '',
      minSpeed: 0,
      maxSpeed: 100
    }
  }),

  getters: {
    hasSelectedUser: (state) => !!state.selectedUserId,
    hasTrajectoryData: (state) => state.trajectoryData.length > 0,
    isTrajectoryPlaying: (state) => state.isPlaying,
    getCurrentSpeed: (state) => state.currentSpeed,
    getCurrentIndex: (state) => state.currentIndex,
    getTrajectoryData: (state) => state.trajectoryData,
    getUserList: (state) => state.userList,
    getQueryParams: (state) => state.queryParams
  },

  actions: {
    setSearchName(name) {
      this.searchName = name
    },

    setSelectedUserId(id) {
      this.selectedUserId = id
    },

    setUserList(users) {
      this.userList = users
    },

    setTrajectoryData(data) {
      this.trajectoryData = data
      this.currentIndex = 0
    },

    setPlaying(status) {
      this.isPlaying = status
    },

    setCurrentSpeed(speed) {
      this.currentSpeed = speed
    },

    setCurrentIndex(index) {
      this.currentIndex = index
    },

    setTrajectoryLayer(layer) {
      this.trajectoryLayer = layer
    },

    setTrajectorySource(source) {
      this.trajectorySource = source
    },

    setMarkerFeature(feature) {
      this.markerFeature = feature
    },

    setMarkerLayer(layer) {
      this.markerLayer = layer
    },

    setMarkerSource(source) {
      this.markerSource = source
    },

    setQueryDialogVisible(visible) {
      this.queryDialogVisible = visible
    },

    setQueryParams(params) {
      this.queryParams = { ...this.queryParams, ...params }
    },

    resetTrajectoryState() {
      this.isPlaying = false
      this.currentSpeed = 1
      this.currentIndex = 0
      this.trajectoryData = []
    },

    updateQueryParams(params) {
      this.queryParams = { ...this.queryParams, ...params }
    }
  }
}) 